package vue;

import java.awt.Dimension;
import java.awt.Graphics;

import java.util.Observable;
import java.util.Observer;

import javax.swing.JPanel;

import controleur.CActionCard;

import modele.MCard;

@SuppressWarnings("serial")
public class VCard extends JPanel implements Observer {
	
	/*
	 * GUI d'une carte
	 */
	
	//Lien vers le modele
	protected MCard cardModel;
	
	public VCard(MCard c) {
		cardModel = c;
		c.addObserver(this);
		//cardModel.
		setPreferredSize(new Dimension(cardModel.getBack().getHeight(), cardModel.getBack().getWidth()));
		
		addMouseListener(new CActionCard(cardModel));
	}
	
	@Override
	public void paintComponent(Graphics g) {
		if(cardModel.isVisible()) {
			if(cardModel.isShowed())
				drawFront(g);
			else
				drawBack(g);
		}
		else {
			setVisible(false);
		}
	}
	
	public void drawFront(Graphics g) {
		g.drawImage(cardModel.getFront(), 0, 0, null);
	}
	
	public void drawBack(Graphics g) {
		g.drawImage(cardModel.getBack(), 0, 0, null);
	}

	@Override
	public void update(Observable arg0, Object arg1) {
		// TODO Auto-generated method stub
		repaint();
		
	}

}
